#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>
using namespace std;

int main()
{
	int n, total = 0, min = 100000000000;
	cin >> n;
	int* num = new int[n+1];
	for (int i = 1; i <= n; i++)
	{
		cin >> num[i];
	}
	for (int i = 1; i <= n; i++)
	{
		total = 0;
		for (int j = 1; j <= n; j++)
		{
			if (i > j)
			{
				total += (j + n - i) * num[j];
			}
			else
			total += (j - i) * num[j];
		}
		if (total < min)
		{
			min = total;
		}
	}
	cout << min;
	return 0;
}